import O1HD from "../../engines/gameEngine";
import level_peopleArchery from "../../levelBundles/level_PeopleArchery/level_peopleArchery";
import PageBase from "../Base/PageBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class PeopleArcheryGetMoneyPage extends PageBase {

    @property({type:cc.Label,tooltip:"金币数量文本"})
    lbNum:cc.Label = null;

    level:level_peopleArchery = null;

    moneyNum:number = 0;

    completeFun:()=>void = null;

    bindLevel(level:level_peopleArchery,moneyNum:number,complteFun:()=>void){
        this.level = level;
        this.moneyNum = moneyNum;
        this.completeFun = complteFun;
        this.refrenshPage();
    }

    refrenshPage(){
        this.lbNum.string = (this.moneyNum + (this.moneyNum * this.level.role.goldAddition)).toString();
    }

    onBtnGet(){
        let addition:number = this.level.role.goldAddition * this.moneyNum;
        let realMoney:number = this.moneyNum + addition;
        console.log(realMoney,"真实的钱");
        O1HD.getManagers().peopleArcheryManager.setData({money:realMoney});
        this.ClosePage();
        this.completeFun && this.completeFun();
    }

    onBtnDouble(){
        let addition:number= this.moneyNum*2 * this.level.role.goldAddition;
        let realMoney:number = this.moneyNum*2 + addition;
        console.log(realMoney,"真实的钱");
        if(O1HD.getServices().userSrv.getCoins() > 0){
            O1HD.getManagers().peopleArcheryManager.setData({money:realMoney});
            this.ClosePage();
            this.completeFun && this.completeFun();
        }else{
            O1HD.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(()=>{
                O1HD.getManagers().peopleArcheryManager.setData({money:realMoney});
                this.ClosePage();
                this.completeFun && this.completeFun();
            },()=>{},null,"看广告获得双倍修为");
        }
    }

}
